import "reflect-metadata";

// 在类上定义元数据
@Reflect.metadata("info", "地球人")
class People {
  @Reflect.metadata("deccible", "居住地为主要城市")
  @Reflect.metadata("deccible1", "上海")
  place = "wangwu";

  @Reflect.metadata("firstname", "第一个名字")
  @Reflect.metadata("lastname", "最后一个名字")
  getFullName(name: string, age: number): string {
    return "kevin";
  }
}

// 获取元数据
console.log(Reflect.getMetadata("info", People));
console.log(Reflect.getMetadata("deccible", People.prototype, "place"));
console.log(Reflect.getMetadata("firstname", People.prototype, "getFullName"));
console.log(Reflect.getMetadata("lastname", People.prototype, "getFullName"));

// 获取People.prototype 上 getFullName方法的全部元数据
console.log(Reflect.getMetadataKeys(People.prototype, "getFullName"));
/*
  [
    'design:returntype',
    'design:paramtypes',
    'design:type',
    'lastname',
    'firstname'
  ]
*/
Reflect.getMetadataKeys(People.prototype, "getFullName").forEach((metakey) => {
  // console.log(metakey);
  console.log(
    "metakey",
    Reflect.getMetadata(metakey, People.prototype, "getFullName")
  );
});

console.log(Reflect.getMetadataKeys(People.prototype, "place"));
Reflect.getMetadataKeys(People.prototype, "place").forEach((metakey) => {
  // console.log(metakey);
  console.log(
    "metakey",
    Reflect.getMetadata(metakey, People.prototype, "place")
  );
});

class ChinesePeople extends People {
  @Reflect.metadata("descible", "姓名不能包含非法汉字")
  guoYear(args: string) {}
}

console.log("getMetadataKeys ==> 查看父类上的方法...");
console.log(Reflect.getMetadataKeys(ChinesePeople.prototype, "getFullName"));
console.log("getOwnMetadataKeys不能查看父类上的方法...");
console.log(Reflect.getOwnMetadataKeys(ChinesePeople.prototype, "getFullName"));

export {};
